//
// Created on 2023/12/25.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#ifndef MyXComponent_Quaternion_H
#define MyXComponent_Quaternion_H

#include "algorithm/Vector3.h"
#include "glm/ext/quaternion_geometric.hpp"
#include <asm-generic/fcntl.h>
#include <asm-generic/stat.h>
#include <asm/stat.h>
#include <sys/stat.h>
class Quaternion {
  private:
    float dataX;
    float dataY;
    float dataZ;
    float dataW;

  public:
    Quaternion(float xData, float yData, float zData, float wData) {
        dataX = xData;
        dataY = yData;
        dataZ = zData;
        dataW = wData;
    }

    Quaternion getNormalized() {
        return normalize(this->dataX, this->dataY, this->dataZ, this->dataW);
    }

    static Quaternion angleAxis(float angleRadians, Vector3 axis) {
        double halfAngleRadians = (double)angleRadians * 0.5;
        float sinValue = (float)sin(halfAngleRadians);
        Vector3 axisMutiplied = Vector3::multiply(axis, sinValue);
        return Quaternion(axisMutiplied.getDataX(), axisMutiplied.getDataY(), axisMutiplied.getDataZ(), (float)cos(halfAngleRadians));
    }
    static float length(float xData, float yData, float zData, float wData) {
        return sqrt(xData * xData + yData * yData + zData * zData + wData * wData);
    }

    static Quaternion Identity() {
        return Quaternion(0.0F, 0.0F, 0.0F, 0.0F);
    }
    static Quaternion nomalize(float xData, float yData, float zData, float wData) {
        float oneOverLen = 1.0F / length(xData, yData, zData, wData);
        return isfinite(oneOverLen) ? Quaternion(xData * oneOverLen, yData * oneOverLen, zData * oneOverLen, wData * oneOverLen)
                                    : Identity();
    }

    float getDataW();
    void setDataW(float dataW);
    float getDataZ();
    void setDataZ(float dataZ);
    float getDataY();
    void setDataY(float dataY);
    float getDataX();
    void setDataX(float dataX);
}; 
#endif // MyXComponent_Quaternion_H
